/**
 * Challenge report script
 */

function acceptChallenge(id){
	document.getElementById('accept_form').set_id.value = id;
}

function reportGame(id, player1, player2){
	var form = document.getElementById('report_form');
	form.set_id.value = id;
	form.player1.value = player1;
	form.player2.value = player2;

	//form.winner.clear();
	form.winner.options[1] = new Option(player1, player1);
	form.winner.options[2] = new Option(player2, player2);
}

//Validate report form
function checkReportForm(form){
	var validate = false;

	if(form.map.value == "none"){
		alert("Please specify a map.");
		form.map.focus();
	}
	else if(form.winner.value == "unplayed"){
		alert("Please specify a winner.");
		form.winner.focus();

	} else if (form.replay.value != ""){
		//A replay wants to be submitted. Check validity
		var replay = form.replay.value;
		var extension = replay.match("\\.\\w+");
		
		if (extension == null || extension.match(/\.SC2Replay/i) == null){
			alert("Invalid replay file format. Format " + extension + " not matching " +format);
			form.replay.focus();
		}
	}
	else return true;

	return false;
}